<template>
	<view>
		<cu-custom bgColor="bg-red" :isBack="true">		<block slot="backText"></block>
			<block slot="content">中奖分红奖励提现</block>
		</cu-custom>
		<block v-if="preview && preview.config.withdraw_is_open == '0'">
			<view class="text-gray text-center margin-xl">服务暂未开启</view>
		</block>
		<block v-else>
			<view class="bg-blue overflow padding text-white text-center relative">
				<view class="margin-tb ">可提现金额</view>
				<view class="text-xl text-bold text-price">{{preview?preview.account.wholesale_money:0}}</view>
				<!-- <view class="absolute blackbg1 loglg padding-xs padding-left-sm" @tap="goPage('/pages/member/withdraw/index')">
					<text class="cuIcon cuIcon-form"></text>提现记录
				</view> -->
			</view>
			<view class="bg-white padding">
				<view class="text-lg">提现金额</view>
				<view class="text-price margin-top text-lg space-between align-center ">
					<input placeholder="请输入提现金额" name="input" class="w100 padding-lr" type="number" step="0.01" v-model="formData.cash"></input>
					<view class="cu-btn round sm bg-blue txbtn" @tap="setAll">全部提现</view>
				</view>
			</view>


			<view class="cu-form-group margin-top">
				<view class="title">提现方式</view>
				<picker @change="PaymentPickerChange" :value="payment_index" :range="paymentPicker">
					<view class="picker">
						{{payment_index>=0?paymentPicker[payment_index]:'请选择支付方式'}}
					</view>
				</picker>
			</view>
			<view class="bg-white margin-top">
				<view class="cu-form-group ">
					<view class="title">姓名<text class="text-red text-lg">*</text></view>
					<input placeholder="请输入姓名" name="input" v-model="formData.realname" class="text-right"></input>
				</view>
				<view class="cu-form-group " v-if="payment_index==1">
					<view class="title">电话<text class="text-red text-lg">*</text></view>
					<input placeholder="请输入电话" name="input" v-model="formData.mobile" class="text-right"></input>
				</view>
				<view class="cu-form-group " v-if="payment_index==1">
					<view class="title">银行卡号<text class="text-red text-lg">*</text></view>
					<input placeholder="请输入银行卡号" name="input" v-model="formData.account_number" class="text-right"></input>
				</view>
				<view class="cu-form-group " v-if="payment_index==1">
					<view class="title">开户行<text class="text-red text-lg">*</text></view>
					<input placeholder="请输入开户行" name="input" v-model="formData.bank_name" class="text-right"></input>
				</view>
			</view>
			<view class="margin-top-xl margin-lr">
				<view class="cu-btn lg w100 bg-blue round shadow" @tap="onSubmit">确认提现</view>

			</view>
			<view class="text-center text-gray margin-top">
				最低提现金额￥{{preview?preview.wholesale_config.wholesale_money_withdraw_lowest_money:'-'}}
				<text>，手续费{{preview?preview.wholesale_config.wholesale_money_withdraw_commission:'-'}}%</text>
			</view>
		</block>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				member: null,
				preview: null,
				CLOUDPATH: this.$config.cloudPath,
				theme: this.$config.THEME(),
				formData: {
					transfer_type: 1,
					cash: 0.00,
					realname: '',
					mobile: '',
					account_number: '',
					bank_name: '',
					is_wholesale: 1,
				},
				payment_index: 0,
				paymentPicker: ['微信', '银行卡'],
			}
		},
		onLoad(options) {
			if (this.$common.loginAuth(true)) {}
		},
		onShow() {
			if (this.$common.loginAuth(true)) {
				this.$common.getMember().then((member) => {
					this.member = member
					this.getDetail()
				})
			}
		},
		methods: {
			onSubmit() {
				let formData = this.formData
				if (formData.cash <= 0) {
					this.$common.showError('请输入提现金额')
					return
				}
				if (!formData.realname.trim()) {
					this.$common.showError('请填写姓名')
					return
				}

				formData.transfer_type = 2
				if (this.payment_index == 1) {
					formData.transfer_type = 1
					if (!formData.mobile.trim()) {
						this.$common.showError('请填写手机号')
						return
					}
					if (!formData.account_number.trim()) {
						this.$common.showError('请输入银行卡号')
						return
					}
					if (!formData.bank_name.trim()) {
						this.$common.showError('请输入开户行')
						return
					}
				}
				uni.showLoading({
					title: '提交中...',
					mask: true
				})
				this.$http
					.post('withdraw', formData)
					.then((response) => {
						uni.hideLoading()
						this.$common.showSuccess('提交成功，请耐心等待审核', (r) => {
							this.getDetail()
						})
						this.$common.rmCache('member')
					})
					.catch((response) => {
						uni.hideLoading()
					})
			},
			getDetail() {
				uni.showLoading({
					title: '加载中...'
				})
				this.$http
					.get('withdraw_preview')
					.then((response) => {
						this.preview = response.data.data
						uni.hideLoading()
					})
					.catch((response) => {
						uni.hideLoading()
					})

			},
			setAll() {
				this.formData.cash = this.preview.account.wholesale_money
			},
			PaymentPickerChange(e) {
				this.payment_index = e.detail.value
			},
		},
	}
</script>

<style>
	.txbtn {
		min-width: 160rpx;
	}

	.loglg {
		right: 0;
		top: 30rpx;
		border-radius: 30rpx 0 0 30rpx;
	}
</style>
